
#ifndef CHANWATCHER_H
#define CHANWATCHER_H

#include <QObject>
#include <QTimer>
#include <QThread>
#include "components/threadid.h"

class MainWindow;
namespace Wishmaster
{
	class Chan;
	class Board;
	class ChanManager;
	class ChanWatcher : public QObject
	{
		Q_OBJECT
	public:
		ChanWatcher();
		virtual ~ChanWatcher();

		void setManager(ChanManager* manager);
		void setView(MainWindow* view);

		bool startTimers();

		enum RefreshPolicy
		{
			rpAllChans = 1,
			rpCurrentChan = 2,
			rpCurrentBoard = 3,
			rpNothing
		};

		void addToWatchList(const ThreadId& threadId);
		void removeFromWatchList(const ThreadId& threadId);
		QList<ThreadId> watchList() const;

	signals:
		void statusMessage(const QString& msg, int timeout = 0);
	
	private slots:
		void autoRefresh();
		void watchRefresh();

	private:
		void refreshAllChans(bool ignoreOverrides);
		void refreshChan(Chan* chan, bool ignoreOverrides);
		void refreshBoard(Board* board);

		ChanManager* m_manager;
		MainWindow* m_view;

		QTimer m_watchTimer;
		QTimer m_swapTimer;
		QTimer m_autoRefreshTimer;
		QThread* m_swapThread;
		QList<ThreadId> m_watchList;
	};
}

#endif

